﻿using System;
using System.Text;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq;
using BudgetData;

namespace BudgetSV.admin.manager
{
    public partial class depart_all_list : ManagePage
    {
        private List<Organization> allList=null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                
                allList = GetAllList(null).ToList();
                List<Organization> IsRole = allList.FindAll(delegate(Organization p) { return p.parent_id == null; });
                createTree(IsRole);
            }
        }

        ////数据绑定
        //private void RptBind()
        //{
        //    BLL.OrganizationBLL bll = new BLL.OrganizationBLL();
        //    IList<Organization> dt = bll.GetAllList(null);
        //    createTree(dt);
        //}

        private void createTree(List<Organization> drs)
        {
            if (drs != null && drs.Count > 0)
            {
                ltTree.Text += "<ul>";
                foreach (var dr in drs)
                {
                    if (dr.parent_id == null) { ltTree.Text += "<li item-expanded='true'>"; }
                    else { ltTree.Text += "<li>"; }
                    
                    ltTree.Text += string.Format(@"<img style='float: left; margin-right: 5px;' src='../skin/default/mailIcon.png' /><span
                                item-title='true'>{0}</span>", dr.name);
                    List<Organization> IsRole = allList.FindAll(delegate(Organization p) { return p.parent_id == dr.id; });
                    createTree(IsRole);
                    ltTree.Text += "</li>";
                }
                ltTree.Text += "</ul>";
            }
        }

    }
}